﻿using System;
using System.Windows.Input;

namespace Labthink.PCSoft.UniversalHost4.Instrument.ViewModel
{
    public class DelegateCommand:ICommand
    {
        private Predicate<object> _canExecute;

        public Action<object> Execute1 { get; set; }

        public DelegateCommand()
        {
        }

        public DelegateCommand(Action<object> execute) : this(execute, null)
        {
        }

        public DelegateCommand(Action<object> execute, Predicate<object> canExecute)
        {
            Execute1 = execute ?? throw new ArgumentNullException("execute");
            _canExecute = canExecute;
        }

        public void Execute(object parameter)
        {
            Execute1(parameter);
        }

        public bool CanExecute(object parameter)
        {
            return _canExecute == null ? true : _canExecute(parameter);
        }

        public event EventHandler CanExecuteChanged
        {
            add { }
            remove { }
        }
    }
}
